<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ include file="/common.jsp"%>
<%@ page contentType="text/html; charset=utf-8" language="java" pageEncoding="utf-8"%>
<%
	request.setCharacterEncoding("utf-8");
	response.setCharacterEncoding("utf-8");
	response.setContentType("text/html; charset=utf-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <title>My JSP 'checkuser.jsp' starting page</title>
    
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  
  <body>
    <%
    	String userName = null;
    	String passWord = null;
    	int userId = -1;
    	
    	userName = request.getParameter("username");
    	passWord = request.getParameter("password");
    	if (userName != null & passWord != null)
    	{
    		try
    		{
	    		Connection con;
	    		PreparedStatement preStmt;
	    		ResultSet rs;
	    		Class.forName("com.mysql.jdbc.Driver");
				DriverManager.registerDriver(new com.mysql.jdbc.Driver());
				String dbUrl = "jdbc:mysql://localhost:3306/class1_1?useUnicode=true&characterEncoding=utf-8";
				String dbUser = "caifeifei";
				String dbPwd = "112997";
				con = java.sql.DriverManager.getConnection(dbUrl, dbUser, dbPwd);
				preStmt = con.prepareStatement("select user_id, name from t_user where name=? and password=?");
				preStmt.setString(1, userName);
				preStmt.setString(2, passWord);
				rs = preStmt.executeQuery();
				if (!rs.next())
				{
					out.println("<b>对不起，您输入的用户名或密码不正确</b>");
				}
				else
				{
					userId = rs.getInt("user_id");
					out.println("成功登陆～！");
					session.setAttribute("username", userName);
				}
				
				out.println(5&1);
				out.println(5&2);
				out.println(5&4);
				con.close();
				preStmt.close();
				rs.close();
			}
			catch(Exception e)
			{
				out.println(e.getMessage());
			}
    	}
    	
    	
    %>
  </body>
</html>
